﻿using System;
using System.Collections;
using System.Collections.Generic;
using BLL;
using Model;
using CrystalDecisions.CrystalReports.Engine;

public partial class ViewbyProduct_ViewPackage_ViewAllUnion : System.Web.UI.Page
{
    private DateTime dt1, dt2;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.Page.Unload += new EventHandler(Page_Unload);
        }
    }

    void Page_Unload(object sender, EventArgs e)
    {
        this.CrystalReportSource1.Dispose();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        dt1 = DateTime.Parse(this.TextBox1.Value.Trim());
        dt2 = DateTime.Parse(this.TextBox2.Value.Trim());
        IList<PackageProductInfo> list = GetQData();
        BindQCR(list);
        this.Label1.Text = list.Count.ToString();
        //BindPIDUID_Q();
    }

    private void BindQCR(IList<PackageProductInfo> list)
    {
        this.CrystalReportSource1.ReportDocument.Load(Server.MapPath("ViewAllUnion.rpt"));

        TextObject txtTestTime = (TextObject)this.CrystalReportSource1.ReportDocument.ReportDefinition.ReportObjects["Text6"];
        txtTestTime.Text = dt1.ToString() + "-" + dt2.ToString();

        this.CrystalReportSource1.ReportDocument.SetDataSource(list);
        this.CrystalReportSource1.DataBind();
        this.CrystalReportViewer1.ReportSource = CrystalReportSource1;
        this.CrystalReportViewer1.DataBind();
        this.CrystalReportViewer1.Visible = true;
    }

    private IList<PackageProductInfo> GetQData()
    {
        IList<PackageProductInfo> oprs = new List<PackageProductInfo>();
        PackageProduct opr = new PackageProduct();
        oprs = opr.GetPackageTestsbyDT(dt1, dt2);
        return oprs;
    }
}
